package com.newlink.building.main.fragment

import android.os.Bundle
import android.view.View
import androidx.recyclerview.widget.GridLayoutManager
import com.newlink.building.common_base.base.BaseFragment
import com.newlink.building.common_base.ext.dividerGridSpace
import com.newlink.building.main.adapter.Module_Main_CategorySecondItemAdapter
import com.newlink.building.main.databinding.FragmentCategorySecondBinding


/**
 * @author mingyan.su
 * @date   2023/3/19 22:31
 * @desc   分类item
 */
class Module_Main_RoomPanelFragment : BaseFragment() {

    private lateinit var mAdapter: Module_Main_CategorySecondItemAdapter
    private lateinit var mBinding: FragmentCategorySecondBinding

    companion object {
        fun newInstance(jsonStr: String): CategorySecondFragment {
            val fragment = CategorySecondFragment()
            val bundle = Bundle()
//            bundle.putString(KEY_LIST, jsonStr)
            fragment.arguments = bundle
            return fragment
        }
    }


    override fun attachLayoutRes(): View {
        mBinding = FragmentCategorySecondBinding.inflate(layoutInflater)
        return mBinding.root
    }

    override fun initView(view: View) {

        mBinding.recyclerView?.apply {
            layoutManager = GridLayoutManager(requireContext(), 2)
            adapter = mAdapter
            dividerGridSpace(2, 8.0f, true)
        }
        mAdapter.onItemClickListener = { _: View, position: Int ->
            val item = mAdapter.getItem(position)
//            if (item != null && !item.link.isNullOrEmpty()) {
//                MainServiceProvider.toArticleDetail(
//                    context = requireContext(),
//                    url = item.link!!,
//                    title = item.title ?: ""
//                )
//            }
        }
    }

    override fun initData() {
//        val listJson = arguments?.getString(KEY_LIST, "")
//        val list = listJson?.toBeanOrNull<MutableList<CategoryItem.CategorySecondItem>>()
//        mAdapter.setData(list)
//        if (list.isNullOrEmpty()) {
//            mBinding.viewEmptyData?.visible()
//        } else {
//            mBinding.viewEmptyData?.gone()
//        }
    }

    override fun lazyLoad() {

    }
}